﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Clustering
{
    public class Cluster
    {
        private int dimension;

        private double error;

        public double Error
        {
            get { return error; }
            set { this.error = value; }
        }
        private double[] center;

        public double[] Center
        {
            get { return center; }
            set { this.center = value; }
        }

        private List<double[]> pointsInCluster = new List<double[]>();

        public List<double[]> PointsInCluster
        {
            get { return pointsInCluster; }
        }

        public double[] CalculateCenter()
        {
            if (pointsInCluster.Count == 0)
                return null;

            this.center = new double[this.dimension];

            for (int i = 0; i < pointsInCluster.Count; i++)
            {
                for (int d = 0; d < this.center.Length; d++)
                {
                    this.center[d] += pointsInCluster[i][d];
                }
            }
            for (int d = 0; d < this.center.Length; d++)
            {
                this.center[d] /= pointsInCluster.Count;
            }

            return this.center;
        }

        public Cluster(int dimension)
        {
            this.dimension = dimension;
        }

    }
}
